package com.jwthhealth_pub.wristband.bloodpressure.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.base.BaseActivity;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.jwthhealth_pub.wristband.bloodpressure.fragment.FragmentBloodPressureDay;
import com.jwthhealth_pub.wristband.bloodpressure.fragment.FragmentBloodPressureMonth;
import com.jwthhealth_pub.wristband.bloodpressure.fragment.FragmentBloodPressureWeek;
import com.jwthhealth_pub.wristband.bloodpressure.fragment.FragmentBloodPressureYear;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.jwthhealth_pub.common.LogUtil.makeLogTag;

/**
 * 血压统计
 * Created by yang on 2017/12/28.
 */

public class BloodPressureStatisticsActivity extends BaseActivity {

    private final String TAG = makeLogTag(BloodPressureStatisticsActivity.class);

    @BindView(R.id.title_layout)
    TitleLayout titleLayout;

    @BindView(R.id.rb_day)
    RadioButton rb_day;
    @BindView(R.id.rb_week)
    RadioButton rb_week;
    @BindView(R.id.rb_month)
    RadioButton rb_month;
    @BindView(R.id.rb_year)
    RadioButton rb_year;

    @BindView(R.id.vpNewsList)
    FrameLayout vpNewsList;
    @BindView(R.id.rgChannel)
    RadioGroup rgChannel;
    int currIndex = -1;
    private List<Fragment> fragmentList=new ArrayList<Fragment>();

    FragmentManager fragmentManager;
     FragmentTransaction fragmentTransaction;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bloodpressurestatis);
        ButterKnife.bind(this);
        initView();
    }

    @Override
    protected void title() {
        titleLayout.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }

    private void initView() {

         fragmentManager = getSupportFragmentManager();
         fragmentTransaction =fragmentManager.beginTransaction();
         fragmentTransaction.add(R.id.vpNewsList,new FragmentBloodPressureDay());
         fragmentTransaction.commit();  //提交修改
        rgChannel.setOnCheckedChangeListener(
                new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup group,
                                                 int checkedId) {
                        switch (checkedId) {
                            case R.id.rb_day:
                                rb_day.setChecked(true);
                                fragmentTransaction =fragmentManager.beginTransaction();
                                fragmentTransaction.replace(R.id.vpNewsList,new FragmentBloodPressureDay());
                                fragmentTransaction.commit();  //提交修改
                                break;
                            case R.id.rb_week:
                                fragmentTransaction =fragmentManager.beginTransaction();
                                fragmentTransaction.replace(R.id.vpNewsList,new FragmentBloodPressureWeek());
                                fragmentTransaction.commit();  //提交修改
                                rb_week.setChecked(true);
                                break;
                            case R.id.rb_month:
                                fragmentTransaction =fragmentManager.beginTransaction();
                                fragmentTransaction.replace(R.id.vpNewsList,new FragmentBloodPressureMonth());
                                fragmentTransaction.commit();  //提交修改
                                rb_month.setChecked(true);
                                break;
                            case R.id.rb_year:
                                fragmentTransaction =fragmentManager.beginTransaction();
                                fragmentTransaction.replace(R.id.vpNewsList,new FragmentBloodPressureYear());
                                fragmentTransaction.commit();  //提交修改
                                rb_year.setChecked(true);
                                break;
                            default:
                                break;
                        }
                    }
                });
    }

    @Override
    public void onBackPressed() {

        super.onBackPressed();
    }
}
